package com.yunshang.ysmall.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.yunshang.ysmall.model.UserInfo;
import com.yunshang.ysmall.service.UserInfoService;
import com.yunshang.ysmall.util.MD5Utils;

@Controller
@RequestMapping("/mng")
public class UserInfoController {
	
	@Resource
	UserInfoService userInfoService;

	@RequestMapping("/login")
	public String mnglogin(){
		return "/mng/login";
	}
	
	@RequestMapping("/index")
	public String index(UserInfo userInfo,Model model){
		userInfo = userInfoService.selectByNameAndPwd(userInfo.getUsername(), MD5Utils.MD5(userInfo.getPassword()));
		if (userInfo == null) {
//			userInfo = new UserInfo();
//			userInfo.setRemark("用户名密码错误");
//			modelAndView = new ModelAndView("/mng/login", "remark", "false");
			model.addAttribute("remark", "login fail");
			return "/mng/login";
		}else{
//			modelAndView = new ModelAndView("/mng/main/index", "userInfo", userInfo);
			model.addAttribute("userInfo", userInfo);
			return "/mng/main/index";
		}
//		return modelAndView;
	}
	
	@RequestMapping("/typelist")
	public String typelist(){
		return "/mng/main/product/typelist";
	}
	
}
